@isTest
private class Test_MobileAppRequestExtension {
    
    private static String requestedForId;
    private static String countryId;
    private static String accountId;
    private static String transactionTypeId;
    private static String contactId;
    private static String occupationId;
    private static String locationId;

    public static void createData() 
    {
        Requested_For__c newRequestedFor = new Requested_For__c();
        newRequestedFor.isActive__c = True;
        newRequestedFor.Type__c = 'Vehicle';
        newRequestedFor.Name = 'Ajman Traffic Department';
        insert newRequestedFor;
        requestedForId = newRequestedFor.Id;
        
        Country__c newCountry = new Country__c();
        newCountry.Name = 'Egypt';
        insert newCountry;
        countryId = newCountry.Id;
        
        Account newAccount = new Account();
        newAccount.Name = 'Test Account';
        insert newAccount;
        accountId = newAccount.Id;
        
        Transaction_Types__c newTransacrionType = new Transaction_Types__c();
        newTransacrionType.Application_Package__c = 'Service Letter';
        newTransacrionType.Application_Type__c = 'Certificate';
        newTransacrionType.Transaction_Description__c = 'Certificate of Incorporation';
        newTransacrionType.isMobile__c = True;
        newTransacrionType.Active__c = True;
        insert newTransacrionType;
        transactionTypeId = newTransacrionType.Id;
        
        Location__c newLocation = new Location__c();
        newLocation.Name = 'Test Location';
        insert newLocation;
        locationId = newLocation.Id;
        
        Contact newContact = new Contact();
        newContact.FirstName = 'Test Contact';
        newContact.LastName = 'Test Contact';
        newContact.AccountId = accountId;
        insert newContact;
        contactId = newContact.Id;
        
        Occupation__c newOccupation = new Occupation__c();
        newOccupation.Name = 'Test Occupation';
        insert newOccupation;
        occupationId = newOccupation.Id;
        
    }
    
    public static void addPageParameters()
    {
        ApexPages.currentPage().getParameters().put('numberOfProducts', '5');
        ApexPages.currentPage().getParameters().put('requestedFor', requestedForId);
        ApexPages.currentPage().getParameters().put('purposeVisit', requestedForId);
        ApexPages.currentPage().getParameters().put('portName', requestedForId);
        ApexPages.currentPage().getParameters().put('requestType', requestedForId);
        ApexPages.currentPage().getParameters().put('oldLicense', requestedForId);
        ApexPages.currentPage().getParameters().put('newLicense', requestedForId);
        ApexPages.currentPage().getParameters().put('vehicleTypeId', requestedForId);
        ApexPages.currentPage().getParameters().put('emirateId', requestedForId);
        ApexPages.currentPage().getParameters().put('addressToId', requestedForId);
        ApexPages.currentPage().getParameters().put('productOne', requestedForId);
        ApexPages.currentPage().getParameters().put('productTwo', requestedForId);
        ApexPages.currentPage().getParameters().put('productThree', requestedForId);
        ApexPages.currentPage().getParameters().put('productFour', requestedForId);
        ApexPages.currentPage().getParameters().put('productFive', requestedForId);
        
        ApexPages.currentPage().getParameters().put('countryId', countryId);
        ApexPages.currentPage().getParameters().put('oldCountry', countryId);
        ApexPages.currentPage().getParameters().put('newCountry', countryId);
        ApexPages.currentPage().getParameters().put('visitingCountry', countryId);
        ApexPages.currentPage().getParameters().put('productOneCountry', countryId);
        ApexPages.currentPage().getParameters().put('productTwoCountry', countryId);
        ApexPages.currentPage().getParameters().put('productThreeCountry', countryId);
        ApexPages.currentPage().getParameters().put('productFourCountry', countryId);
        ApexPages.currentPage().getParameters().put('productFiveCountry', countryId);
        
        ApexPages.currentPage().getParameters().put('transactionTypeId', transactionTypeId);
        
        ApexPages.currentPage().getParameters().put('contact', contactId);
        ApexPages.currentPage().getParameters().put('permitEmployeeOne', contactId);
        ApexPages.currentPage().getParameters().put('permitEmployeeTwo', contactId);
        ApexPages.currentPage().getParameters().put('permitEmployeeThree', contactId);
        ApexPages.currentPage().getParameters().put('permitEmployeeFour', contactId);
        ApexPages.currentPage().getParameters().put('permitEmployeeFive', contactId);
        
        ApexPages.currentPage().getParameters().put('previousJobId', occupationId);
        
        ApexPages.currentPage().getParameters().put('newLocation', locationId);
        
        ApexPages.currentPage().getParameters().put('productOneInvoice', 'Test');
        ApexPages.currentPage().getParameters().put('productTwoInvoice', 'Test');
        ApexPages.currentPage().getParameters().put('productThreeInvoice', 'Test');
        ApexPages.currentPage().getParameters().put('productFourInvoice', 'Test');
        ApexPages.currentPage().getParameters().put('productFiveInvoice', 'Test');
        
        ApexPages.currentPage().getParameters().put('productOneShipment', 'Test');
        ApexPages.currentPage().getParameters().put('productTwoShipment', 'Test');
        ApexPages.currentPage().getParameters().put('productThreeShipment', 'Test');
        ApexPages.currentPage().getParameters().put('productFourShipment', 'Test');
        ApexPages.currentPage().getParameters().put('productFiveShipment', 'Test');
        
        ApexPages.currentPage().getParameters().put('productOneDate', '2014-08-08');
        ApexPages.currentPage().getParameters().put('productTwoDate', '2014-08-08');
        ApexPages.currentPage().getParameters().put('productThreeDate', '2014-08-08');
        ApexPages.currentPage().getParameters().put('productFourDate', '2014-08-08');
        ApexPages.currentPage().getParameters().put('productFiveDate', '2014-08-08');
        
        ApexPages.currentPage().getParameters().put('delivery', 'Courier');
    }
    
    // Methods for testing
    public static testMethod void testMobileAppRequestExtension() {
        
        createData();
        
        PageReference pageRef = Page.MobileApp_Open_BankLetter_Confirm;   
        Test.setCurrentPage(pageRef);
        
        addPageParameters();
        
        Request__c newRequest = new Request__c();
        
        //RecordType requestRecordType = [SELECT Id FROM RecordType WHERE SObjectType = 'Request__c' AND DeveloperName LIKE '%Certificate%' LIMIT 1];
        //newRequest.Submission_Channel__c = 'Mobile App';
        //newRequest.Requested_For__c = newRequestedFor.Id;
        //insert newRequest;
        
        ApexPages.StandardController requestStandardController = new ApexPages.StandardController(newRequest);
        MobileAppRequestExtension requestExtension = new MobileAppRequestExtension(requestStandardController);
        
        requestExtension.saveAndThankYou();
   }
}